<template>
  <article class="page">
    <headerbar>支部纪事</headerbar>
    <section class="frame-content-sub no-bg">

      <section class="inner-content pdv-9 pdh-4">

        <!--<div class="input-row-wrap">
          <div class="name">标题：</div>
          <input v-model="form.title" type="text" placeholder="请填写标题">
        </div>-->

        <div class="input-row-wrap">
          <div class="name">内容：</div>
          <textarea v-model="form.spaceExt" placeholder="请填写内容" name="" id="" cols="30" rows="10"></textarea>
        </div>

    <!--    <div class="input-row-wrap">
          <div class="name">附件：</div>
          <section class="upload-wrap">
            <cube-upload ref="upload"
                         action=""
                         accept="*/*"
                         :simultaneous-uploads="1"
                         @files-added="uploadFile"
            />
          </section>
        </div>-->



        <div class="pdv-6"></div>

        <div @click="save($event)" v-preventReClick="1000" class="default-block-btn">提交</div>

        <div class="pdv-5"></div>
      </section>

    </section>
  </article>
</template>

<script>
  export default {
    name: 'learningExperiencesAdd',
    data () {
      return {
        form: {
          title: '',
          spaceExt: '',
          annexInfo: '',
          spaceType: '2'
        },
        attachmentList: []
      }
    },
    created () {
      let id = this.$route.query.id
      if (id) {
        this.form.title = this.$store.state.branchDetail.title
        this.form.spaceExt = this.$store.state.branchDetail.ext
        this.form.annexInfo = this.$store.state.branchDetail.annexInfo
        this.form.spaceId = id
      }
    },
    methods: {
      uploadFile (file) {
        let uploadFile = file[0]
        let formData = new FormData()
        formData.append('file', uploadFile)
        this.fetchService.o_upload(formData).then((res) => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          let ret = res.data
          let data = {
            fileid: ret.fileId,
            filename: uploadFile.name
          }
          this.attachmentList.push(data)
        })
      },
      save (e) {
        if (e.target.disabled) {
          return false
        }
       /* if (this.form.title === '') {
          return this.tools.tip('请填写标题')
        }*/
        if (this.form.spaceExt === '') {
          return this.tools.tip('请填写内容')
        }
        this.form.annexInfo = JSON.stringify(this.attachmentList)
        console.log('---------------this.form.annexInfo=', this.form.annexInfo)
        this.fetchService.saveSpaceInfo(this.form).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message)
          }
          this.tools.tip('提交成功')
          this.tools.back()
        })
      }
    }
  }
</script>

<style scoped>

</style>
